/****************************************************************************
**
** This file is part of qPhotoTag, a photo keywording application
**
** Copyright (C) 2009 Marcell Lengyel <miketkf@gmail.com>
**
** GNU General Public License
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**
****************************************************************************/

#ifndef CAPTIONEDIT_H
#define CAPTIONEDIT_H
/*! \file captionedit.h
    \brief This file contains the declaration of the CaptionEdit class
 */

#include <QPlainTextEdit>

//! A widget for editing IPTC Captions
/*!
  A QPlainTextEdit subclass, that emits the captionEditChanged() signal
  if the focus is lost and the text was changed between focus-gain and
  focus-lost.
 */
class CaptionEdit : public QPlainTextEdit
{
    Q_OBJECT
public:
    //! CaptionEdit constructor
    /*!
      The constructor accepts one argument, the parent widget.
      On MacOS X it sets the FrameStyle to QFrame::NoFrame
      \param parent a QWidget pointer to the parent object
     */
    CaptionEdit(QWidget *parent = 0);
protected:
    //! Overriding the focusInEvent handler
    /*!
      In the focusInEvent the content of the QPlainTextEdit is stored to
      the caption local variable. It will be used in the focusOutEvent for
      comparison to see if there was a change.

      \param e is a QFocusEvent pointer
      \sa focusOutEvent()
     */
    void focusInEvent(QFocusEvent *e);
    //! Overriding the focusOutEvent handler
    /*!
      In the focusOutEvent the content of the QPlainTextEdit is compared to
      the stored caption local variable. If there is a difference, the
      captionEditChanged() signal is emitted.

      \param e is a QFocusEvent pointer
      \sa focusInEvent() and captionEditChanged()
     */
    void focusOutEvent(QFocusEvent *e);
signals:
    //! Emitted if the content was changed between focus-gain and focus-lost
    /*!
      The captionEditChanged() signal is emitted in focusOutEvent(), if the
      content of the QPlainTextEdit was changed between focus-gain and focus-lost.
     */
    void captionEditChanged();
private:
    //! A private variable used for storing the content at focusInEvent
    /*!
      The content of the QPlainTextEdit is stored in this variable for comparison
      to check whether the content was changed between focus-gain and focus-lost.
      /sa focusInEvent()
     */
    QString caption;
};

#endif // CAPTIONEDIT_H
